﻿using PhotoGallery.Data.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PhotoGallery.Data.Repository
{
    public class BaseRepository
    {
        protected const string 
            //UploadsFolder = "App_Data\\Galleries\\",
            UploadsUrl = "~/Uploads/Galleries/",
            AlbumsXml = "AlbumsMetaData.xml",
            DefaultAlbumPicture = "empty_album.png",
            DefaultPhotoPicture = "empty_image.png",
            AppDataFolder = "App_Data\\",
            SystemFolder = "\\App_Data\\System\\";

        protected string BasePath 
        { 
            get
            {
                return System.AppDomain.CurrentDomain.BaseDirectory;
            } 
        }

        protected string Owner { get;set;}

        protected string getAlbumFolder(Album album)
        {
            if (album.FolderName == null || album.FolderName == String.Empty)
            {
                return Settings.AlbumFolder + album.ID+"\\";
            }
            else
            {
                return album.FolderName + "\\";
            }
        }

        protected string getAlbumUrl(Album album)
        {
            if (album.FolderName == String.Empty)
            {
                return "album" + album.ID.ToString() + "/";
            }
            else
            {
                return album.FolderName + "/";
            }
        }

        protected string ConvertDate(DateTime? date)
        {
            if (date.HasValue)
            {
                DateTime dtDate = date ?? DateTime.Now;
                string strDate = dtDate.Year.ToString() + "-" + dtDate.Month.ToString() + "-" + dtDate.Day.ToString();
                return strDate;
            }
            else
            {
                return "";
            }
        }

        protected DateTime? ConvertDate(string date)
        {
            if (String.IsNullOrWhiteSpace(date))
            {
                return null;
            }
            else
            {
                DateTime ddate = DateTime.Parse(date);
                return ddate;
            }
        }
    }
}